class ThoughtRecord {
  final int? id;
  final String thought;
  final List<String> distortionLabels;
  final int emotionalIntensity;
  final DateTime timestamp;
  String? balancedView;
  String? actionPlan;
  List<String>? reflectionAnswers;
  String? positiveThought;

  ThoughtRecord({
    this.id,
    required this.thought,
    required this.distortionLabels,
    required this.emotionalIntensity,
    required this.timestamp,
    this.balancedView,
    this.actionPlan,
    this.reflectionAnswers,
    this.positiveThought,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'thought': thought,
      'distortion_labels': distortionLabels.join(','),
      'emotional_intensity': emotionalIntensity,
      'timestamp': timestamp.toIso8601String(),
      'balanced_view': balancedView,
      'action_plan': actionPlan,
      'reflection_answers': reflectionAnswers?.join('|||'),
      'positive_thought': positiveThought,
    };
  }

  factory ThoughtRecord.fromMap(Map<String, dynamic> map) {
    return ThoughtRecord(
      id: map['id'] as int?,
      thought: map['thought'] as String,
      distortionLabels: (map['distortion_labels'] as String).split(','),
      emotionalIntensity: map['emotional_intensity'] as int,
      timestamp: DateTime.parse(map['timestamp'] as String),
      balancedView: map['balanced_view'] as String?,
      actionPlan: map['action_plan'] as String?,
      reflectionAnswers: map['reflection_answers'] != null
          ? (map['reflection_answers'] as String).split('|||')
          : null,
      positiveThought: map['positive_thought'] as String?,
    );
  }

  ThoughtRecord copyWith({
    int? id,
    String? thought,
    List<String>? distortionLabels,
    int? emotionalIntensity,
    DateTime? timestamp,
    String? balancedView,
    String? actionPlan,
    List<String>? reflectionAnswers,
    String? positiveThought,
  }) {
    return ThoughtRecord(
      id: id ?? this.id,
      thought: thought ?? this.thought,
      distortionLabels: distortionLabels ?? List<String>.from(this.distortionLabels),
      emotionalIntensity: emotionalIntensity ?? this.emotionalIntensity,
      timestamp: timestamp ?? this.timestamp,
      balancedView: balancedView ?? this.balancedView,
      actionPlan: actionPlan ?? this.actionPlan,
      reflectionAnswers: reflectionAnswers != null ? List<String>.from(reflectionAnswers) : this.reflectionAnswers,
      positiveThought: positiveThought ?? this.positiveThought,
    );
  }

  @override
  String toString() {
    return 'ThoughtRecord{id: $id, thought: $thought, distortionLabels: $distortionLabels, emotionalIntensity: $emotionalIntensity, balancedView: $balancedView, actionPlan: $actionPlan, reflectionAnswers: $reflectionAnswers, positiveThought: $positiveThought}';
  }
} 